 <?php
 class Common_Model extends CI_Model{
     function __construct(){
         parent::__construct();
         $this->load->database();
     }
     public function search($table,$where){
         $this->db->where($where);
         $query=$this->db->get($table);
         return $query->result_array();
     }
     public function pageGet($table,$where=null,$start,$limit){
         $rs = $this->db->simple_query("select * from ".$table." limit ".$start.','.$limit);
		 $result = $rs->fetchAll();
         return $result;
     }
     
     /*
      *  $idmap 是形如下面的关联数组？！
      *  $array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
	  *
	  *  查询条件组的用法
		 $this->db->select('*')->from('my_table')
		 ->group_start()
		 ->where('a', 'a')
		 ->or_group_start()
		 ->where('b', 'b')
		 ->where('c', 'c')
		 ->group_end()
		 ->group_end()
		 ->where('d', 'd')
		 ->get();
	  *
      */
     public function findOne($table,$idmap){
         $this->db->where($idmap['key'],$idmap['value']);
         $this->db->select('*');
         $query=$this->db->get($table);
         $one=$query->row_array();
         return $one;
     }
 
     public function addData($table,$data){
         return $this->db->insert($table,$data);
     }
 
     public function modify($table,$data,$where){
         $this->db->where($where);
         return $this->db->update($table,$data);
     }
 
     public function remove($idmap,$table){
         if(is_array($idmap['value'])){
             $ids=implode($id, ',');
             $this->db->where($idmap['key'].' in','('.$idmap['value'].')');
             $this->db->delete($table,array($idmap['key'].' in','('.$idmap['value'].')'));
         }else{
             $this->db->delete($table,array($idmap['key'],$idmap['value']));
         }
     }
 }
